package no.uib.kwikktaim.core;

import no.uib.kwikktaim.gui.MainWindow;
import no.uib.kwikktaim.utils.PlayerOptions;

/**
 * Thread that checks and updates the time slider
 */
public class TimeChecker implements Runnable {

	private MainWindow mw;

	public TimeChecker(MainWindow mw) {
		this.mw = mw;
	}

	@Override
	public void run() {
		while(true) {
			if(mw.getPlaypause() == PlayerOptions.PLAY) {
				if(mw.model.getSize() == 0)
					continue;
				mw.setTimeSlider(mw.getTime());
				if(mw.getTotalTime() <= mw.getTime()) { // Time to play next track!
					mw.listPlayList.setSelectedIndex((mw.listPlayList.getSelectedIndex()+1)%mw.model.getSize());
					mw.loadAndPlay();
				}
			}
		}

	}

}
